new Vue({
    el: '#app',
    data: {
        isCollapse: true,
        patientname: '',
        idcard: '',
        isloading: false,
        showmsg: false,
        showrelation: false,
        patientMsg: {
            address: '',
            sex: '男',
            age: '',
            jcbNum: '',//基础病
            phone: '',
            email: '',
            jcNum: '',//检测次数
            grgl: '',//感染概率
            grglTemp: '',
            zlqk: '',//治疗情况
            glqk: '',//隔离情况
        },
        returnMsg: {
            patientname: '',
            idcard: '',
        },
        newDialogVisible: false,
        newPersonXqDialogVisible: false,
        newAreaXqDialogVisible: false,
        newTrafficXqDialogVisible: false,
        newSome: '1',
        contactorData: {
            contactorName: '',
            contactorIdCard: '',
            contactTime: '',
            contactName: '',
            contactNameCn: '',
            contactorPhone: '',
            duration: '',//接触时长
            tfqk: '',//接触环境的通风情况
            kzqk: '',//口罩
            dfkz: '',//对方口罩
        },
        contactType:
            [{
                value: 'common',
                label: '无亲密接触',
            }, {
                value: 'talk',
                label: '面对面交谈',
            }, {
                value: 'handshake',
                label: '握手',
            }, {
                value: 'embrace',
                label: '拥抱',
            }, {
                value: 'kiss',
                label: '接吻及以上',
            }],
        xqContactorData: {
            contactorName: '',
            contactorIdCard: '',
            contactTime: '',
            contactName: '',
            contactNameCn: '',
            contactorPhone: '',
            duration: '',//接触时长
            tfqk: '',//接触环境的通风情况
            kzqk: '',//口罩
            dfkz: '',
            createDay:'',//数据创建日期
        },
        contactorTable: [],
        areaTable: [],
        trafficTable: [],
        sfkbj: '1',//输入框是否禁用 1禁用 2启用
        countNum: {
            contactCount: 0,
            reachCount: 0,
            trafficCount: 0,
        },
        pagesize: 5,
        searchData: '',
        searchAreaData: '',
        searchTrafficData: '',
        areaData: {
            addressName: '',
            xqAddress: '',
            reachTime: '',
            leaveTime: '',
            kzqk: '',
            tfqk: '',
        },
        xqAreaData: {
            addressName: '',
            xqAddress: '',
            reachTime: '',
            leaveTime: '',
            relationId: '',
            areaId: '',
            kzqk: '',
            tfqk: '',
        },
        trainNumber: [],
        trainNumberTemp: [],//所有车次数据
        trainValue: '',
        formData: {
            pageIndex: 1,
            pageSize: 10,
        },//懒加载
        trainCityData: {
            trainNumber: '',
            startCity: '',
            endCity: '',
            startStation: '',
            endStation: '',
            startTime: '',
            endTime: '',
            trafficType: '',
            relationId: '',
            trafficId: '',
        },
        transportationFacility:
            [{
                value: 1,
                label: '火车',
            }, {
                value: 2,
                label: '飞机',
            }],
        jichubing:
            [{
                value: '0',
                label: '健康',
            }, {
                value: '1',
                label: '有一个基础病',
            }, {
                value: '2',
                label: '有两个基础病',
            }, {
                value: '3',
                label: '有三个基础病',
            }, {
                value: '4',
                label: '有四个基础病',
            }, {
                value: '5',
                label: '有五个及以上的基础病',
            }],
        tongfeng:
            [{
                value: 'sntflh',
                label: '室内通风良好',
            }, {
                value: 'sntfjc',
                label: '室内通风较差',
            }, {
                value: 'snbtf',
                label: '室内不通风',
            }, {
                value: 'shiwai',
                label: '室外',
            }],
        kzlx:
            [{
                value: 'bkz',
                label: '布口罩',
            }, {
                value: 'n95',
                label: 'N95或者KN95口罩',
            }, {
                value: 'kn99',
                label: 'KN99',
            }, {
                value: 'qtkz',
                label: '其他口罩',
            }, {
                value: 'n95hxf',
                label: '带呼吸阀的N95口罩',
            }, {
                value: 'no',
                label: '未戴口罩',
            }],
        trainorplant: 1,
    },
    methods: {
        handleOpen: function (key, keyPath) {

        },
        handleClose: function (key, keyPath) {

        },
        getAddress: function (province, city, area) {
            var _this = this;
            $.ajax(
                {
                    url: 'http://api.map.baidu.com/location/ip',
                    data: {
                        coor: 'bd09ll',
                        ak: '3tnSxTxwk3wv5tm7F1N3upqd5nMDqBcl',
                        ip: ''
                    },
                    type: 'get',
                    dataType: 'jsonp',
                    async: true,
                    success: function (data) {
                        if (data.status == 0) {
                            if (province == null) {

                                $('#citys').citys({
                                    type: 'name', province: data.content.address_detail.province,
                                    city: data.content.address_detail.city
                                });
                            } else {

                                $('#citys').citys({
                                    type: 'name', province: province,
                                    city: city, area: area
                                });
                            }
                        } else {
                            $('#citys').citys();
                            alert('获取地址失败，您的ip可能不在中国大陆');
                        }
                    },
                    error: function (data) {
                        alert('获取地址失败');
                        $('#citys').citys();
                    }
                }
            );
        },
        createpatient: function () {
            var _this = this;
            _this.isloading = true;
            _this.contactorTable = [];
            _this.areaTable = [];
            _this.trafficTable = [];
            _this.countNum.contactCount = 0;
            $.ajax({
                url: 'entry/createorquery',
                data: {
                    patientName: _this.patientname,
                    IDCard: _this.idcard,
                },
                type: 'post',
                dataType: 'Json',
                async: true,
                success: function (data) {
                    console.log(data)
                    _this.isloading = false;
                    if (data.code == 1) {
                        _this.returnMsg.patientname = data.name;
                        _this.returnMsg.idcard = data.idCard;
                        _this.patientMsg.sex = data.sex;
                        _this.patientMsg.age = data.age;
                        _this.patientMsg.jcbNum = data.jcbNum;
                        _this.patientMsg.phone = data.phone;
                        _this.patientMsg.email = data.email;
                        _this.patientMsg.jcNum = data.jcNum;
                        _this.patientMsg.grglTemp = data.grgl;
                        _this.patientMsg.glqk = data.glqk;
                        if (data.grgl != 1.0) {
                            _this.patientMsg.grgl = '0.0';
                        } else {
                            _this.patientMsg.grgl = data.grgl;
                        }
                        if (data.zlqk == 'zy') {
                            _this.patientMsg.grgl = '2';
                        }
                        _this.showmsg = true;

                        if (data.address == null) {
                            _this.getAddress(null, null, null)
                        } else {
                            var strs = new Array();
                            strs = data.address.split("|");
                            if (strs.length == 2) {
                                $('#citys').citys({
                                    type: 'name', province: strs[0],
                                    city: strs[1],
                                    area: strs[1]
                                })
                            } else {
                                $('#citys').citys({
                                    type: 'name', province: strs[0],
                                    city: strs[1],
                                    area: strs[2]
                                });
                            }

                        }
                        _this.cxPerson();
                        _this.cxArea();
                        _this.cxTraffic();
                    } else if (data.code == 4) {
                        _this.$message.error('身份证已存在，与姓名不符');
                        _this.showmsg = false;
                        _this.showrelation = false;
                    } else if (data.code == 2) {
                        _this.$message.error('系统异常');
                        _this.showmsg = false;
                        _this.showrelation = false;
                    }

                },
                error: function (data) {
                    _this.isloading = false;
                    _this.showmsg = false;
                    _this.showrelation = false;
                }
            });

        },
        cxPerson: function (skipNum = 0, limitNum = 5) {
            var _this = this;
            _this.contactorTable = [];
            $.ajax({
                url: 'entry/getrelation',
                data: {
                    patientIdCard: _this.returnMsg.idcard,
                    skip: skipNum,
                    limit: limitNum,
                    searchData: _this.searchData,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    console.log(data)
                    _this.countNum.contactCount = data[data.length - 1].count;
                    if (data[data.length - 1].code == 1) {
                        for (var i = data.length - 2; i >= 0; i--) {
                            var contactname;
                            var contactorPhone;
                            if (data[i].value.contactName == 'kiss') {
                                contactname = "亲吻及以上"
                            } else if (data[i].value.contactName == 'talk') {
                                contactname = "面对面交谈"
                            } else if (data[i].value.contactName == 'handshake') {
                                contactname = "握手"
                            } else if (data[i].value.contactName == 'embrace') {
                                contactname = "拥抱"
                            } else {
                                contactname = '无亲密接触'
                            }
                            if (data[i].value.contactorPhone == null) {
                                contactorPhone = "未填写手机号"
                            } else {
                                contactorPhone = data[i].value.contactorPhone;
                            }
                            var contactorObject = {
                                contactTime: data[i].value.contactTime,
                                name: data[i].value.name,
                                idCard: data[i].value.idCard,
                                contactName: data[i].value.contactName,
                                contactNameCn: contactname,
                                contactorPhone: contactorPhone,
                                duration: data[i].value.duration,
                                tfqk: data[i].value.tfqk,
                                kzqk: data[i].value.kzqk,
                                dfkz: data[i].value.dfkz,
                                createDay: data[i].value.createDay,
                            };
                            _this.contactorTable.push(contactorObject);
                        }

                    }
                    _this.showrelation = true;

                },
                error: function (data) {
                }
            });
        },
        cxArea: function (skipNum = 0, limitNum = 5) {
            var _this = this;
            _this.areaTable = [];
            $.ajax({
                url: 'entry/getarearelation',
                data: {
                    patientIdCard: _this.returnMsg.idcard,
                    skip: skipNum,
                    limit: limitNum,
                    searchAreaData: _this.searchAreaData,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    console.log(data)
                    _this.countNum.reachCount = data[data.length - 1].count;
                    if (data[data.length - 1].code == 1) {
                        for (var i = data.length - 2; i >= 0; i--) {
                            if (data[i].contactName == 'reach') {
                                var areaObject = {
                                    addressName: data[i].addressName,
                                    xqAddress: data[i].xqAddress,
                                    contactName: data[i].contactName,
                                    leaveTime: data[i].leaveTime,
                                    reachTime: data[i].reachTime,
                                    areaId: data[i].areaId,
                                    relationId: data[i].relationId,
                                    kzqk: data[i].kzqk,
                                    tfqk: data[i].tfqk,
                                };
                                _this.areaTable.push(areaObject);
                            }
                        }

                    }
                    _this.showrelation = true;

                },
                error: function (data) {
                }
            });

        },
        cxTraffic: function (skipNum = 0, limitNum = 5) {
            var _this = this;
            _this.trafficTable = [];
            $.ajax({
                url: 'entry/gettrafficrelation',
                data: {
                    patientIdCard: _this.returnMsg.idcard,
                    skip: skipNum,
                    limit: limitNum,
                    searchTrafficData: _this.searchTrafficData,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    console.log(data)
                    _this.countNum.trafficCount = data[data.length - 1].count;
                    if (data[data.length - 1].code == 1) {
                        for (var i = data.length - 2; i >= 0; i--) {
                            if (data[i].contactName == 'byTrain') {
                                var trafficObject = {
                                    trainNumber: data[i].trainNumber,
                                    contactName: data[i].contactName,
                                    trafficType: data[i].trafficType,
                                    startCity: data[i].startCity,
                                    endCity: data[i].endCity,
                                    startStation: data[i].startStation,
                                    endStation: data[i].endStation,
                                    startTime: data[i].startTime,
                                    endTime: data[i].endTime,
                                    trafficId: data[i].trafficId,
                                    relationId: data[i].relationId,
                                };
                                _this.trafficTable.push(trafficObject);
                            }
                        }

                    }
                    _this.showrelation = true;

                },
                error: function (data) {
                }
            });
        },
        submitMsg: function () {
            var _this = this;
            var provinceoptions = $('#province option:selected');
            var cityoptions = $('#city option:selected');
            var areaoptions = $('#area option:selected');
            if (typeof (areaoptions.val()) == "undefined") {
                _this.patientMsg.address = provinceoptions.val() + '|' + cityoptions.val();
            } else {
                _this.patientMsg.address = provinceoptions.val() + '|' + cityoptions.val() + '|' + areaoptions.val();
            }
            if (_this.patientMsg.grgl == 1.0) {
                _this.patientMsg.grglTemp = 1.0;
            }
            if (_this.patientMsg.grgl == 2) {
                _this.patientMsg.zlqk = 'zy';
                _this.patientMsg.grglTemp = 0.0;
            } else {
                _this.patientMsg.zlqk = '';
            }
            $.ajax({
                url: 'entry/setmsg',
                data: {
                    patientName: _this.returnMsg.patientname,
                    IDCard: _this.returnMsg.idcard,
                    address: _this.patientMsg.address,
                    sex: _this.patientMsg.sex,
                    age: _this.patientMsg.age,
                    jcbNum: _this.patientMsg.jcbNum,
                    phone: _this.patientMsg.phone,
                    email: _this.patientMsg.email,
                    jcNum: _this.patientMsg.jcNum,
                    grgl: _this.patientMsg.grglTemp,
                    zlqk: _this.patientMsg.zlqk,
                    glqk: _this.patientMsg.glqk,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                    } else {
                        _this.$message.error('提交失败');
                    }
                },
                error: function (data) {
                    _this.$message.error('提交失败');
                }
            });
        },
        newDialog1: function () {
            var _this = this;
            // _this.contactorData.contactorName = '';
            // _this.contactorData.contactTime = '';
            // _this.contactorData.contactorIdCard = '';
            // _this.areaData.addressName = '';
            // _this.areaData.xqAddress = '';
            // _this.areaData.reachTime = '';
            // _this.areaData.leaveTime = '';
            _this.QINGKONGDUIXIANGZHI(_this.contactorData);
            _this.QINGKONGDUIXIANGZHI(_this.areaData);
            _this.QINGKONGDUIXIANGZHI(_this.trainCityData);
            _this.trainValue = '';
            _this.formData.pageIndex = 1;
            _this.newDialogVisible = true;

        },
        /**
         * 接触则详情页
         * @param {} rowData 
         */
        newDialog2: function (rowData) {
            console.log(rowData);
            var _this = this;
            _this.QINGKONGDUIXIANGZHI(_this.xqContactorData);
            _this.sfkbj = '1';
            _this.xqContactorData.contactorName = rowData.name;
            _this.xqContactorData.contactorIdCard = rowData.idCard;
            _this.xqContactorData.contactTime = rowData.contactTime;
            _this.xqContactorData.contactName = rowData.contactName;
            _this.xqContactorData.contactNameCn = rowData.contactNameCn;
            _this.xqContactorData.contactorPhone = rowData.contactorPhone;
            _this.xqContactorData.duration = rowData.duration;
            _this.xqContactorData.tfqk = rowData.tfqk;
            _this.xqContactorData.kzqk = rowData.kzqk;
            _this.xqContactorData.dfkz = rowData.dfkz;
            _this.newPersonXqDialogVisible = true;
        },
        /**
         * 地区详情编辑
         */
        newDialog3: function (rowData) {
            console.log(rowData);
            var _this = this;
            _this.sfkbj = '1';
            _this.xqAreaData.xqAddress = rowData.xqAddress;
            _this.xqAreaData.addressName = rowData.addressName;
            _this.xqAreaData.reachTime = rowData.reachTime;
            _this.xqAreaData.leaveTime = rowData.leaveTime;
            _this.xqAreaData.relationId = rowData.relationId;
            _this.xqAreaData.areaId = rowData.areaId;
            _this.xqAreaData.kzqk = rowData.kzqk;
            _this.xqAreaData.tfqk = rowData.tfqk;
            _this.newAreaXqDialogVisible = true;
        },
        /**
         * 交通工具详情编辑
         * @param {*} rowData 
         */
        newDialog4: function (rowData) {
            console.log(rowData);
            var _this = this;
            _this.QINGKONGDUIXIANGZHI(_this.trainCityData);
            _this.trainCityData.trafficType = rowData.trafficType;
            _this.trainCityData.trainNumber = rowData.trainNumber;
            _this.trainCityData.startCity = rowData.startCity;
            _this.trainCityData.endCity = rowData.endCity;
            _this.trainCityData.startStation = rowData.startStation;
            _this.trainCityData.endStation = rowData.endStation;
            _this.trainCityData.startTime = rowData.startTime;
            _this.trainCityData.endTime = rowData.endTime;
            _this.trainCityData.relationId = rowData.relationId;
            _this.trainCityData.trafficId = rowData.trafficId;
            _this.sfkbj = '1';
            _this.newTrafficXqDialogVisible = true;
        },
        /**
         * 创建患者接触的人
         */
        newContactor: function () {
            var _this = this;
            $.ajax({
                url: 'entry/createrelation',
                data: {
                    patientIdCard: _this.returnMsg.idcard,
                    contactorName: _this.contactorData.contactorName,
                    contactName: _this.contactorData.contactName,
                    contactTime: _this.contactorData.contactTime,
                    contactorIdCard: _this.contactorData.contactorIdCard,
                    duration: _this.contactorData.duration,
                    tfqk: _this.contactorData.tfqk,
                    kzqk: _this.contactorData.kzqk,
                    dfkz: _this.contactorData.dfkz,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.newDialogVisible = false;
                        _this.cxPerson();
                    } else if (data.code == 2) {
                        _this.$message.error('接触者身份证已存在，但姓名不符');
                    } else {
                        _this.$message.error('系统异常');
                    }

                },
                error: function (data) {

                }
            });
        },
        /**
         * 创建患者去过的地区
         */
        newArea: function () {
            var _this = this;
            var provinceoptions = $('#reachprovince option:selected');
            var cityoptions = $('#reachcity option:selected');
            var areaoptions = $('#reacharea option:selected');
            if (typeof (areaoptions.val()) == "undefined") {
                _this.areaData.addressName = provinceoptions.val() + '|' + cityoptions.val();
            } else {
                _this.areaData.addressName = provinceoptions.val() + '|' + cityoptions.val() + '|' + areaoptions.val();
            }
            $.ajax({
                url: 'entry/addnewarea',
                data: {
                    addressName: _this.areaData.addressName,
                    xqAddress: _this.areaData.xqAddress,
                    reachTime: _this.areaData.reachTime,
                    leaveTime: _this.areaData.leaveTime,
                    patientIdCard: _this.returnMsg.idcard,
                    contactName: 'reach',
                    kzqk: _this.areaData.kzqk,
                    tfqk: _this.areaData.tfqk,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.cxArea();
                        _this.newDialogVisible = false;
                    } else {
                        _this.$message.error('系统异常');
                    }
                },
                error: function (data) {
                    _this.$message.error('系统异常');
                }
            });

        },
        tableRowClassName: function () {
            return 'rowbg';
        },
        deleterelation: function (rowData) {
            var _this = this;
            this.$confirm('此操作将永久删除该关系, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                $.ajax({
                    url: 'entry/deleterelation',
                    data: {
                        patientIdCard: _this.returnMsg.idcard,
                        contactName: rowData.contactName,
                        contactorIdCard: rowData.idCard,
                        createDay: rowData.createDay,

                    },
                    type: 'post',
                    dataType: 'Json',
                    success: function (data) {
                        if (data.code == 1) {
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            _this.cxPerson();
                        } else if (data.code == 2) {
                            _this.$message.error('删除失败');
                        }

                    },
                    error: function (data) {
                        _this.$message.error('系统异常');
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        deleteArearRelation: function (rowData) {
            console.log(rowData);
            var _this = this;
            this.$confirm('此操作将永久删除该关系, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                $.ajax({
                    url: 'entry/deletearearelation',
                    data: {
                        patientIdCard: _this.returnMsg.idcard,
                        contactName: rowData.contactName,
                        xqAddress: rowData.xqAddress,
                        addressName: rowData.addressName,
                    },
                    type: 'post',
                    dataType: 'Json',
                    success: function (data) {
                        if (data.code == 1) {
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            _this.cxArea();
                        } else if (data.code == 2) {
                            _this.$message.error('删除失败');
                        }

                    },
                    error: function (data) {
                        _this.$message.error('系统异常');
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        deleteTrafficRelation: function (rowData) {
            console.log(rowData);
            var _this = this;
            this.$confirm('此操作将永久删除该关系, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                $.ajax({
                    url: 'entry/deletetrafficrelation',
                    data: {
                        relationId: rowData.relationId,
                    },
                    type: 'post',
                    dataType: 'Json',
                    success: function (data) {
                        if (data.code == 1) {
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            _this.cxTraffic();
                        } else if (data.code == 2) {
                            _this.$message.error('删除失败');
                        }

                    },
                    error: function (data) {
                        _this.$message.error('系统异常');
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        handleCurrentChange: function (currentPage) {
            var _this = this;
            _this.cxPerson((currentPage - 1) * _this.pagesize, _this.pagesize);
        },
        handleAreaCurrentChange: function (currentPage) {
            var _this = this;
            _this.cxArea((currentPage - 1) * _this.pagesize, _this.pagesize);
        },
        handleTrafficCurrentChange: function (currentPage) {
            var _this = this;
            _this.cxTraffic((currentPage - 1) * _this.pagesize, _this.pagesize);
        },
        cxPersonChange: function () {
            var _this = this;
            _this.cxPerson();
        },
        cxAreaChange: function () {
            var _this = this;
            _this.cxArea();
        },
        cxTrafficChange: function () {
            var _this = this;
            _this.cxTraffic();
        },
        /**
         * 在dialog打开的时候初始化下拉框 
         */
        bjareainit: function () {
            var _this = this;
            var addarea = _this.xqAreaData.addressName.split("|");
            if (addarea.length == 2) {
                $('#bjreachcitys').citys({ type: 'name', province: addarea[0], city: addarea[1], area: addarea[1] });
            } else if (addarea.length == 3) {
                $('#bjreachcitys').citys({ type: 'name', province: addarea[0], city: addarea[1], area: addarea[2] });
            }
        },
        trainselectinit: function (formData, search = '') {
            var _this = this;
            if (search == '') {
                _this.trainNumber = _this.trainNumberTemp.slice(0, formData.pageIndex * formData.pageSize);
            } else {
                _this.trainNumber = [];
                _this.formData.pageIndex = 1;
                for (var i = 0; i < _this.trainNumberTemp.length; i++) {
                    if (_this.trainNumberTemp[i].train_number.indexOf(search) >= 0) {
                        _this.trainNumber.push(_this.trainNumberTemp[i]);
                    }
                }

            }
        },
        /** 懒加载
         * 
         */
        loadmore: function () {
            this.formData.pageIndex++;
            this.trainselectinit(this.formData);
        },
        trainfilter: function (val) {
            this.trainselectinit(this.formData, val);
        },
        getTrainCity: function (value) {
            var _this = this;
            if (value !== '') {
                for (var i = 0; i < _this.trainNumberTemp.length; i++) {
                    if (_this.trainNumberTemp[i].train_number == value) {
                        _this.trainCityData.startCity = _this.trainNumberTemp[i].start_city;
                        _this.trainCityData.endCity = _this.trainNumberTemp[i].end_city;
                        _this.trainCityData.trainNumber = value;
                    }
                }
            } else {
                _this.trainNumber = [];
                _this.formData.pageIndex = 1;
                _this.trainNumber = _this.trainNumberTemp.slice(0, _this.formData.pageIndex * _this.formData.pageSize);
                _this.trainCityData.startCity = '';
                _this.trainCityData.endCity = '';
                _this.trainCityData.trainNumber = '';
            }
        },
        getTrainData() {
            var _this = this;
            var url = 'plugins/train_number.json';
            $.getJSON(url, function (data) {
                _this.trainNumberTemp = data;
                _this.trainselectinit(_this.formData);
            });
        },
        createTrainRelation: function () {
            var _this = this;
            if (_this.trainorplant == 1) {
                var contactName = 'byTrain'
            }
            $.ajax({
                url: 'entry/createTrainRelation',
                data: {
                    patientIdCard: _this.returnMsg.idcard,
                    trainNumber: _this.trainCityData.trainNumber,
                    startCity: _this.trainCityData.startCity,
                    endCity: _this.trainCityData.endCity,
                    startStation: _this.trainCityData.startStation,
                    endStation: _this.trainCityData.endStation,
                    startTime: _this.trainCityData.startTime,
                    endTime: _this.trainCityData.endTime,
                    contactName: contactName,
                    trafficType: _this.transportationFacility[_this.trainorplant - 1].label
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.cxTraffic();
                        _this.newDialogVisible = false;
                    } else {
                        _this.$message.error('系统异常');
                    }

                }, error: function (data) {
                    _this.$message.error('系统异常');
                }
            });
        },
        bjTraffic: function () {
            var _this = this;
            console.log(_this.trainCityData)
            $.ajax({
                url: 'entry/updatedtraffic',
                data: {
                    startStation: _this.trainCityData.startStation,
                    endStation: _this.trainCityData.endStation,
                    startTime: _this.trainCityData.startTime,
                    endTime: _this.trainCityData.endTime,
                    id: _this.trainCityData.relationId,
                    trafficId: _this.trainCityData.trafficId,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.cxTraffic();
                        _this.newTrafficXqDialogVisible = false;
                    } else {
                        _this.$message.error('系统异常');
                    }
                }, error: function (data) {
                    _this.$message.error('系统异常');
                }
            })
        },
        bjArea: function () {
            var _this = this;
            var provinceoptions = $('#bjreachprovince option:selected');
            var cityoptions = $('#bjreachcity option:selected');
            var areaoptions = $('#bjreacharea option:selected');
            if (typeof (areaoptions.val()) == "undefined") {
                _this.xqAreaData.addressName = provinceoptions.val() + '|' + cityoptions.val();
            } else {
                _this.xqAreaData.addressName = provinceoptions.val() + '|' + cityoptions.val() + '|' + areaoptions.val();
            }
            $.ajax({
                url: 'entry/updateArea',
                data: {
                    areaId: _this.xqAreaData.areaId,
                    relationId: _this.xqAreaData.relationId,
                    addressName: _this.xqAreaData.addressName,
                    xqAddress: _this.xqAreaData.xqAddress,
                    reachTime: _this.xqAreaData.reachTime,
                    leaveTime: _this.xqAreaData.leaveTime,
                    kzqk: _this.xqAreaData.kzqk,
                    tfqk: _this.xqAreaData.tfqk,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.cxArea();
                        _this.newAreaXqDialogVisible = false;
                    } else {
                        _this.$message.error('系统异常');
                    }
                }, error: function (data) {
                    _this.$message.error('系统异常');
                }
            })
        },
        bjPerson: function () {
            var _this = this;
            console.log(_this.xqContactorData)
            $.ajax({
                url: 'entry/updatePerson',
                data: {
                    patientIdCard: _this.returnMsg.idcard,
                    contactorIdCard: _this.xqContactorData.contactorIdCard,
                    contactName: _this.xqContactorData.contactName,
                    contactTime: _this.xqContactorData.contactTime,
                    contactorPhone: _this.xqContactorData.contactorPhone,
                    duration: _this.xqContactorData.duration,
                    tfqk: _this.xqContactorData.tfqk,
                    kzqk: _this.xqContactorData.kzqk,
                    dfkz: _this.xqContactorData.dfkz,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if (data.code == 1) {
                        _this.$message({
                            showClose: true,
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.cxPerson();
                        _this.newPersonXqDialogVisible = false;
                    } else {
                        _this.$message.error('系统异常');
                    }
                }, error: function (data) {
                    _this.$message.error('系统异常');
                }
            })
        },
        selectPage: function (key, keyPath) {
            $(window).attr('location', keyPath);
        },



        QINGKONGDUIXIANGZHI: function (obj) {
            for (var key in obj) {
                obj[key] = '';
            }
        }
    },


    watch: {
        newSome: function () {
            if (this.newSome == 2) {
                $('#reachcitys').citys({ type: 'name' });
            }
        },
    },
    mounted() {
        this.getTrainData();
    },
    directives: {
        'el-select-loadmore': {
            bind(el, binding) {                // 获取element-ui定义好的scroll盒子
                const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
                SELECTWRAP_DOM.addEventListener('scroll', function () {
                    /**
                    * scrollHeight 获取元素内容高度(只读)                    
                    * scrollTop 获取或者设置元素的偏移值,常用于, 计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.
                    * clientHeight 读取元素的可见高度(只读)                    
                    * * 如果元素滚动到底, 下面等式返回true, 没有则返回false:                    
                    * * ele.scrollHeight - ele.scrollTop === ele.clientHeight;                    
                    * */
                    const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1;
                    if (condition) {
                        binding.value();
                    }
                });
            }
        }
    },
})